<template>
	<view class="diaContent" :style="{ display: show ? 'block' : 'none' }">
		<view class="info">
			<image class="close"  @click="handleCose" style="z-index: 99;" :src="'https://file.aavisa.com/001/images/entryOrder/close.png'" mode="heightFix" />
			<view class="title">转发信息安全设置</view>
			<view class="password">
				<view class="input">
					<view class="passwordTitle">设置密码：</view>
					<input type="text" v-model="password" placeholder="请设置打开链接密码" placeholder-style="color:#AEB3BB" />
				</view>
			</view>

			<view class="selectTime">
				<view class="selectTimeList">
					<view class="item" v-for="item in list" :key="item.id"
						:class="expireTime === item.id ? 'activeItem' : ''" @click="expireTime = item.id">
						{{ item.name }}
					</view>
				</view>
			</view>

			<view class="prompt">
				<view class="box">注</view>
				<text>温馨提示</text>
			</view>

			<view class="infoPrompt">
				<view>1、可以在手机端和电脑端轻松填写 </view>
				<view>2、每次复制,上次链接自动失效。</view>
			</view>
			<view class="btn" @click="SaveSecurityUrl">
				<view>生成安全链接并复制</view>
			</view>
		</view>
	</view>
</template>

<script>
	let app = getApp()
	import {
	orderList,
	delOrder,
	delPassenger,
	cancelOrder,
	SaveSecurityUrl
} from '@/api/order.js'
	export default {
		name: "Dialog",
		props: {
			show: {
				type: Boolean,
				default: false
			},
			orderId: {
				type: String,
				default: ""
			},
			url:{
				type:String,
				default:""
			}

		},
		data() {
			return {
				password: "",
				expireTime: 1,
				password: "",
				errpassword: "",
				list: [{
						id: 1,
						name: "一天有效",
					},
					{
						id: 2,
						name: "一周有效",
					},
					{
						id: 3,
						name: "一月有效",
					},
				],
			};
		},
		methods: {
			handleCose() {
				console.log("handleCose")
				this.password = "";
				this.expireTime = 1;
				this.$emit("close", false);
			},
			SaveSecurityUrl() {
			if (!this.password) {
			
				app.showToast('请输入密码')
				return
			}

			uni.showLoading({
				title: '生成链接中'
			})

			// 调用后端API生成安全链接
			SaveSecurityUrl({
				url: this.url,
				password: this.password,
				expireTime: parseInt(this.expireTime)
			}).then(res => {
				uni.hideLoading()
				this.urlShow = false
				if (res.status === 200) {
					uni.setClipboardData({
						data: res.data.url,
						success: () => {
							app.showToast('链接已复制到剪贴板')
							this.handleCose()
						}
					})
				} else {
					app.showToast(res.message || '生成链接失败')
				}
			}).catch(() => {
				uni.hideLoading()
				app.showToast('网络错误，请重试')
			})
		},
		}
	};
</script>

<style lang="scss" scoped>
	$imgUrl: "https://file.aavisa.com/001";

	.diaContent {
		width: 100%;
		height: 100%;
		border-radius: 30rpx;
		font-family: PingFang SC;
		padding: 0 48rpx;
		z-index: 999;
		.info {
			margin-top: 40rpx;
			position: relative;

			.close {
				width: 22rpx;
				height: 22rpx;
				position: absolute;
				top: 8rpx;
				right: -2rpx;
			}

			.title {
				text-align: center;
				font-weight: bold;
				font-size: 30rpx;
				color: #000000;
			}

			.password {
				margin-top: 32rpx;

				.passwordTitle {
					width: 168rpx;
					font-weight: bold;
					font-size: 30rpx;
					color: #000000;
				}

				.input {
					height: 100rpx;
					background: #F7F7F9;
					border-radius: 20rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 0 32rpx;

					input {
						// font-weight: 500;
						font-size: 32rpx;
						color: #49596d;


					}

					.icon_img1 {
						width: 38rpx;
						height: 38rpx;
					}
				}
			}

			.selectTime {
				margin-top: 34rpx;

				.selectTimeList {
					display: flex;
					justify-content: space-between;

					.item {
						display: flex;
						justify-content: center;
						align-items: center;
						position: relative;

						width: 199rpx;
						height: 78rpx;
						background: #f7f7f9;
						border-radius: 10rpx;
						// font-weight: 500;
						font-size: 30rpx;
						color: #49596d;
						margin-right: 15rpx;
					}

					.item:last-child {
						margin-right: 0;
					}

					.activeItem {
						background: rgba(28, 113, 244, 0.1);
						border: 1px solid #1c71f4;
						color: #1c71f4;
						font-weight: 500
					}
				}
			}

			.prompt {
				font-size: 26rpx;
				color: #808785;
				display: flex;
				align-items: center;
				margin: 46rpx 0 21rpx 0;

				.box {
					width: 36rpx;
					height: 36rpx;
					background: #1c71f4;
					display: flex;
					justify-content: center;
					align-items: center;
					border-radius: 6rpx;
					margin-right: 14rpx;
					font-weight: 500;
					font-size: 24rpx;
					color: #ffffff;
				}

				text {
					font-weight: bold;
					font-size: 28rpx;
					color: #101d34;
				}
			}

			.infoPrompt {
				padding: 24rpx 0 0 0;
				border-top: 1px dashed rgba(140, 148, 161, 0.2);
				font-size: 26rpx;
				color: #808785;
				line-height: 41rpx;
			}

			.btn {
				// padding: 0 48rpx;
				margin-top: 47rpx;

				view {
					width: 629rpx;
					height: 94rpx;
					background: #1c71f4;
					border-radius: 47rpx;
					font-weight: 500;
					font-size: 36rpx;
					color: #ffffff;
					display: flex;
					justify-content: center;
					align-items: center
				}
			}
		}
	}
</style>